package com.Gui;

import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Graphics;
import java.awt.Image;
import java.io.File;
import java.io.IOException;

import javax.imageio.ImageIO;
import javax.swing.JFrame;
import javax.swing.JPanel;

public class GameFrame {
    // 定义 属性 画笔
    private JPanel panel;

    public GameFrame() {
        try {
            this.initUI();
            this.initPlayGround();
            this.drawPlayGround();
            this.initClick();
        }catch (IOException e) {
            throw new RuntimeException(e);
        }catch (InterruptedException e) {
            throw new RuntimeException(e);
        }
    }


    // 定义方法
    // 创建窗口的方法
    public void initUI() throws IOException{
        this.setTitle("五子棋游戏");
        this.setIconImage(ImageIO.read(new File("D:/icon.jpg")));
        this.setSize(900,900);
        this.setLocation(150,20);
        this.setResizable(false);
        this.setDefaultCloseOperation(EXIT_ON_CLOSE);
        this.setLayout(new BorderLayout());
        this.setVisible(true);
    }

    // 创建笔
    public void initPlayGround() {
        this.panel = new JPanel();
        this.panel.setSize(900,900);
        this.add(panel,BorderLayout.CENTER);
    }


    // 画棋盘
    public void drawPlayGround() throws InterruptedException{
        Thread.sleep(1000);
        Graphics g = panel.getGraphics();
        g.setColor(Color.ORANGE);
        g.fillRect(0,0,900,900);
        g.setColor(Color.BLACK);
        for (int i = 0; i < 15; i++) {
            g.drawLine(100, 70 + (i * 50), 800, 70 + (i * 50));
        }
        for (int i = 0; i < 15; i++) {
            g.drawLine(100 + (i * 50), 70, 100 + (i * 50), 770);
        }
    }

    // 点击方法
    public void initClick() {
        this.panel.addMouseListener(new MyCLicKListener());
    }



}
